import 'package:bruno/bruno.dart';
import 'package:common/common.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../audio_card/container_tab_indicator.dart';
import 'wallet_histor_page.dart';

/// @description:
/// @author
/// @date: 2023-11-24 15:12:22
class WalletHistoryMainPage extends StatefulWidget {
  const WalletHistoryMainPage({Key? key}) : super(key: key);

  @override
  State<WalletHistoryMainPage> createState() => _WalletHistoryMainPageState();
}

class _WalletHistoryMainPageState extends State<WalletHistoryMainPage> with TickerProviderStateMixin {
  late TabController _tabController;
  final List<Widget> _pages = [];

  late String category;

  final List<String> _tabs = ['全部', '支出', '收入'];

  @override
  void initState() {
    super.initState();
    _pages.add(const WalletHistoryPage(inorout: '-1', key: PageStorageKey('全部')));
    _pages.add(const WalletHistoryPage(inorout: '0', key: PageStorageKey('支出')));
    _pages.add(const WalletHistoryPage(inorout: '1', key: PageStorageKey('收入')));
    _tabController = TabController(length: _pages.length, vsync: this);

    int index = Get.arguments ?? 0;
    _tabController.index = index;
  }

  @override
  void dispose() {
    super.dispose();
    _tabController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Container(
          height: double.infinity,
          alignment: Alignment.center,
          decoration: BoxDecoration(
              gradient: const LinearGradient(colors: [
                Color(0xFF000000),
                Color(0xFF3C2F2F),
              ], begin: Alignment.topCenter, end: Alignment.bottomCenter),
              borderRadius: BorderRadius.circular(25)),
        ),
        Scaffold(
          backgroundColor: Colors.transparent,
          appBar: BrnAppBar(title: _tabbarWarpper(), backgroundColor: Colors.transparent, elevation: 0),
          body: TabBarView(
              controller: _tabController,
              children: _pages.map((e) {
                return e;
              }).toList()),
        ),
      ],
    );
  }

  Widget _tabbarWarpper() {
    return DefaultTabController(
      length: _pages.length,
      child: Container(
        color: Colors.transparent,
        // height: 40,
        child: TabBar(
          tabAlignment: TabAlignment.start,
          controller: _tabController,
          labelColor: Colors.white,
          indicatorColor: Colors.black,
          unselectedLabelColor: Colors.white.withOpacity(0.56),
          isScrollable: true,
          indicatorWeight: 0,
          // indicator: const UnderlineTabIndicator(
          //   borderSide: BorderSide(color: Colors.black, width: 5.0),
          //   insets: EdgeInsets.symmetric(horizontal: 10.0), // 设置指示器的水平间距
          // ),
          overlayColor: WidgetStateProperty.resolveWith((states) {
            return Colors.transparent;
          }),
          dividerHeight: 0,
          indicator: ContainerTabIndicator(
              color: const Color(0xFF22F2EB),
              width: 30.w,
              height: 3.w,
              radius: const BorderRadius.all(Radius.circular(14.0)),
              padding: const EdgeInsets.only(left: 0.0, right: 0, top: 15, bottom: 0)),
          labelStyle: const TextStyle(color: Color(0xFF000000), fontSize: 15, fontWeight: FontWeight.w500),
          unselectedLabelStyle: const TextStyle(color: Color(0xFF999999), fontSize: 15, fontWeight: FontWeight.w500),
          onTap: (index) {
            logs(index);
          },
          tabs: List.generate(_tabs.length, (index) {
            // return Tab(text: _tabs[index]);
            return Tab(child: Text(_tabs[index]));
          }),
        ),
      ),
    );
  }
}
